// 像素鸟元素基类
class BaseRectangle {

  constructor(width, height, left, top, xSpeed, ySpeed, dom) {
    this.width = width;
    this.height = height;
    this.left = left;
    this.top = top;
    this.xSpeed = xSpeed;
    this.ySpeed = ySpeed;
    this.dom = dom;
    this.render();
  }


  /**
   * 渲染函数
   */
  render() {
    this.dom.style.width = this.width + "px";
    this.dom.style.height = this.height + "px";
    this.dom.style.left = this.left + "px";
    this.dom.style.top = this.top + "px";
  }


  /**
   * 移动
   */
  move(duration) {
    this.left = this.left + this.xSpeed * duration;
    this.top = this.top + this.ySpeed * duration;

    // 判断属性
    if (typeof this.onMove === 'function') {
      // 每次移动后都会调用该方法
      this.onMove();
    }

    // 重新渲染
    this.render();
  }
}